import dayjs, { type Dayjs, type ManipulateType } from 'dayjs';
import type { SliderDataType } from '../slider/types';

const getEmptyArray = (len = 1) => {
  return Array.from({ length: len });
}

const getDates = (unit: ManipulateType, range = 1) => {
  const now = dayjs();
  const items = getEmptyArray(range);
  return items.map<Dayjs>((_, i) => now.add(i, unit));
}

export const getYears = (range = 20) => {
  const dates = getDates('year', range);
  return dates.map<SliderDataType<Dayjs>>(value => {
    const label = value.year();
    return { value, label };
  });
}